package com.loveyukari.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.loveyukari.model.Auth;
import com.loveyukari.service.AuthService;
import com.loveyukari.service.YukariLogService;
import com.loveyukari.support.JsonResult;

import net.sf.json.JSONObject;

/**
*
*yangshaohua
*2017年2月6日下午5:54:44
**/
@Controller
@RequestMapping("/admin/chatmsg")
public class ChatmsgController {
	
	@Autowired
	private AuthService authService;
	
	@RequestMapping("/index")
	public String index(Model model,String key){
		model.addAttribute("key", key);
		return "chatmsg/index";
	}
	
	@RequestMapping("/find")
	@ResponseBody
	public JsonResult<Object> findChatmsg(String name,boolean fuzzy,String dateStr){
		List<JSONObject> list = authService.getAuthTalk(name, fuzzy);
		if(list.isEmpty()){
			return  new JsonResult<Object>(1,"用户未发言");
		}
		return new JsonResult<Object>(0, "", list);
	}
	
	@RequestMapping("/getAuthTalk")
	@ResponseBody
	public JsonResult<Object> getAuthTalk(int authId){
		Auth auth = authService.getCacheAuth(authId);
		if (auth != null){
			JSONObject jsonObject = new JSONObject();
			List<JSONObject> list = authService.getAuthTalk(auth.getId());
			if(list.isEmpty()){
				return  new JsonResult<Object>(1,"用户未发言");
			}
			jsonObject.put("name", auth.getName());
			jsonObject.put("talkList", list);
			return new JsonResult<Object>(0,"",jsonObject);
		} else {
			return new JsonResult<Object>(-1,"未找到用户");
		}
		
	}
	
	

}
